package com.lagou.edu.service.impl;

import com.lagou.edu.service.GuavaRedisService;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

public class GuavaRedisServiceImpl implements GuavaRedisService{

	private JedisCluster jcd;

	public static GuavaRedisService getInstance() {
		return new GuavaRedisServiceImpl();
	}



	private GuavaRedisServiceImpl() {
		JedisPoolConfig config = new JedisPoolConfig();
		Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
		jedisClusterNode.add(new HostAndPort("172.16.1.165", 7001));
		jedisClusterNode.add(new HostAndPort("172.16.1.165", 7002));
		jedisClusterNode.add(new HostAndPort("172.16.1.165", 7003));
		jcd = new JedisCluster(jedisClusterNode, config);
	}

	@Override
	public void displayCache() {
		System.out.println("no.....");
	}

	@Override
	public Object get(String key) {
		return jcd.get(key);
	}

	@Override
	public void put(String key, Object value) {
		jcd.setex(key, 30, value.toString());
	}
}
